package com.itzxx.huazhun.ui.record.valuation

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartModel
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartType
import com.itzxx.huazhun.R
import com.itzxx.huazhun.data.model.RecordChildBean
import com.itzxx.huazhun.databinding.ActivityRecordValuationBinding
import com.itzxx.huazhun.databinding.ActivityRecordValuationLocalBinding
import com.itzxx.huazhun.ui.record.curve.CurveAnalysisActivity
import com.itzxx.library_base_ktx.base.activity.BaseVmDbActivity

class RecordValuationLocalActivity :
    BaseVmDbActivity<RecordValuationLocalViewModel, ActivityRecordValuationLocalBinding>() {

    companion object {
        fun startActivity(context: Context, type: Int, list: ArrayList<Int>) {
            val instent = Intent(
                context,
                RecordValuationLocalActivity()::class.java
            )
            instent.putExtra("type", type)
            instent.putIntegerArrayListExtra("list", list)
            context.startActivity(
                instent
            )
        }
    }

    lateinit var aaChartModel: AAChartModel

    override fun initView(savedInstanceState: Bundle?) {
        setSupportActionBar(mDatabind.tbHead)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        aaChartModel = AAChartModel()
            .chartType(AAChartType.Line)
            .backgroundColor("#ffffff")
            .dataLabelsEnabled(false)
            .legendEnabled(false)
            .yAxisTitle("")
    }

    override fun onResume() {
        super.onResume()
        intent?.run {
            val parcelableArrayListExtra = getIntegerArrayListExtra("list")
            val intExtra = getIntExtra("type",0)
            parcelableArrayListExtra?.let {
                mViewModel.getCurveListData(it)
                mViewModel.getLocalData(intExtra,it)
            }
        }
    }
    override fun createObserver() {
        mViewModel.run {
            curveDataCategoriesLiveData.observe(this@RecordValuationLocalActivity) {
                runOnUiThread {
                    aaChartModel.categories(it.toTypedArray())
                    mDatabind.aaChartView.aa_drawChartWithChartModel(aaChartModel)
                }

            }

            curveDataLiveData.observe(this@RecordValuationLocalActivity) {
                runOnUiThread {
                    aaChartModel.series(it.toArray())
                    mDatabind.aaChartView.aa_drawChartWithChartModel(aaChartModel)
                }
            }
        }
    }

    override fun databind2ViewModel() {
        super.databind2ViewModel()
        mDatabind.viewmodel = mViewModel
    }

    override fun onSupportNavigateUp(): Boolean {
        finish()
        return true
    }

    override fun isApplyDefaultWaitDialog(): Boolean {
        return true
    }
}